import GetResource from '@renderer/utils/bundle/getResource'
// 字体加载
const loadFont = (fontName: string, ab: ArrayBuffer) => {
  return async () => {
    const fontLoader = new FontFace(fontName, ab)
    try {
      await fontLoader.load()
      document.fonts.add(fontLoader)
      return fontLoader
    } catch (error) {
      return Promise.reject(error)
    }
  }
}
// const fontInfo = [
//   { name: 'RZFont', url: 'src/assets/font/锐字云字库行楷GB.ttf' },
//   { name: 'XQFont', url: 'src/assets/font/喜鹊聚珍体.ttf' },
// ]
// export default async (): Promise<void> => {
//   await Promise.all(fontInfo.map((info) => loadFont(info.name, info.url)()))
// }

export default async (): Promise<void> => {
  const fontInfo = await GetResource.getFonts()
  await Promise.all(Object.entries(fontInfo).map(([name, url]) => loadFont(name, url)()))
}
